﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CustomControlz.Validations;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.DXErrorProvider;
using Utilities;

namespace CustomControlz.XtraEditors.LookUps
{
    public partial class ccGridLookUpEdit : GridLookUpEdit
    {
        private ClsGlobalEnums.EDataSourceType _lucType = ClsGlobalEnums.EDataSourceType.Default;
        public ccGridLookUpEdit()
        {
            InitializeComponent();
        }


        void ccGridLookUpEdit_HandleCreated(object sender, EventArgs e)
        {
            var oCommFn = new ClsCommonFn();
            oCommFn.GridLookUpSetting(this, ShowAutoFilterRow);

            if (ProvideValidation && ValidationProvider != null)
            {
                ValidationProvider.SetValidationRule(this, new IsNullOrEmpty()
                {
                    ErrorText = string.Format("Please Select {0}", Text),
                    ErrorType = ErrorType.Warning,
                    CaseSensitive = false
                });
            }
        }
        private void ccGridLookUpEdit_Popup(object sender, EventArgs e)
        {
            var oCommFn = new ClsCommonFn();
            oCommFn.ClearColumnFilter(sender, ClsCommonUiFn.EGridType.Normal);
        }


        public bool ShowAutoFilterRow { get; set; }
        public bool ProvideValidation { get; set; }
        public ccDxValidationProvider ValidationProvider { get; set; }
        public Int32 Value
        {
            get
            {
                if (EditValue != null)
                    return Convert.ToInt32(EditValue);
                return 0;
            }

            set { }
        }

        public ClsGlobalEnums.EDataSourceType LucType
        {
            get { return _lucType; }
            set
            {
                _lucType = value;
                SetNullText();
            }
        }

        private void SetNullText()
        {
            switch (_lucType)
            {
                case ClsGlobalEnums.EDataSourceType.AccGroups:
                    Properties.NullText = "[ SELECT ACCOUNT GROUP ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Accounts:
                    Properties.NullText = "[ SELECT ACCOUNT ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Vendor:
                    Properties.NullText = "[ SELECT VENDOR ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Cities:
                    Properties.NullText = "[ SELECT CITY ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.ItemTypes:
                    Properties.NullText = "[ SELECT ITEM TYPE ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Items:
                    Properties.NullText = "[ SELECT ITEM ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Stores:
                    Properties.NullText = "[ SELECT STORE ]";
                    break;
                case ClsGlobalEnums.EDataSourceType.Units:
                    Properties.NullText = "[ SELECT UNIT ]";
                    break;
            }
        }
    }
}
